# coding=utf-8
import threading
import queue
import csv
import time
import random


#获取cookie
class MoreHeader(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)

    def _read_file(self):
        '''
        :return: list
        '''
        with open('secret.csv', 'r', encoding='utf-8') as fp:
            for index, i in enumerate(csv.reader(fp)):
                if index == 0:
                    continue
                else:
                    yield i

    def write_data(self):
        with open('NewHeader.csv') as fp:
            pass
        pass

    def run(self):
        '''
        这里将一个账号作为一个对象去获取cookie,每次创建5个线程去获取cookie,
        利用queue模拟生产者消费者模式来实现
        :return: None
        '''
        pass


class Producer(threading.Thread):
    """
    Producer thread 制作线程
    """
    def __init__(self, t_name, queue):
        threading.Thread.__init__(self, name=t_name)
        self.data = queue

    def run(self):
        for i in range(5):  # 生成0-4五条队列
            print("%s: %s is producing %d to the queue!" % (time.ctime(), self.getName(), i))  # 当前时间t生成编号d并加入队列
            self.data.put(i)  # 写入队列编号
            time.sleep(random.randrange(10) / 5)  # 随机休息
        print("%s: %s producing finished!" % (time.ctime(), self.getName))  # 编号d队列完成制作


class Consumer(threading.Thread):
    """
    Consumer thread 执行线程
    """
    def __init__(self, t_name, queue):
        threading.Thread.__init__(self, name=t_name)
        self.data = queue

    def run(self):
        for i in range(5):
            val = self.data.get()
            print("%s: %s is consuming. %d in the queue is consumed!" % (time.ctime(), self.getName(), val))  # 编号d队列已经被消费
            # time.sleep(random.randrange(10))
        print("%s: %s consuming finished!" % (time.ctime(), self.getName()))  # 编号d队列完成消费


def main():
    q = queue.Queue()
    p = Producer('qwe', q)
    c = Consumer('qwe', q)
    p.run()
    c.run()


if __name__ == '__main__':

    # main()
    print('Error' in ['Error'] and False)
    pass